Imports System.Runtime.Serialization


Namespace DataStream
    ''' <summary>
    ''' Holds information (String and Class) for the Calculator to 
    ''' Parse on each calculation required.
    ''' </summary>
    ''' <remarks></remarks>
    <Serializable()> _
    Public Class StreamCalculatorItem

        Private mEvalString As String = ""

        <NonSerialized()> _
        Private mEvalObject As StreamCalculatorObject = Nothing

        <NonSerialized()> _
        Private mEvalReason As String = ""

        ''' <summary>
        ''' Performs an evalulation to create the evaluation object on creation
        ''' </summary>
        ''' <param name="sc"></param>
        ''' <remarks></remarks>
        <OnDeserialized()> _
        Private Sub OnDeserialized(ByVal sc As StreamingContext)
            Try
                If mEvalString <> "" Then
                    mEvalObject = New StreamCalculatorObject(mEvalString)
                End If
            Catch ex As StreamCalculatorObjectParseException
                Debug.Print("StreamCalculatorItem: (OnDeserialized) cannot parse stream object")
            End Try
        End Sub

        Sub New(ByVal EvalString As String)
            EvaluationString = EvalString
        End Sub

        Public Property EvaluationString() As String
            Get
                Return mEvalString
            End Get
            Set(ByVal value As String)
                mEvalString = value

                Try
                    Dim obj As New StreamCalculatorObject(value)
                    mEvalObject = obj
                    mEvalReason = Nothing
                Catch ex As StreamCalculatorObjectParseException
                    mEvalObject = Nothing
                    mEvalReason = ex.Description
                End Try

            End Set
        End Property

        ''' <summary>
        ''' Returns the evaluation object
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property EvalObject() As StreamCalculatorObject
            Get
                Return mEvalObject
            End Get
        End Property

        ''' <summary>
        ''' Returns a status if the evaluation object is valid
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property EvalValid() As Boolean
            Get
                Return Not IsNothing(mEvalObject)
            End Get
        End Property

        ''' <summary>
        ''' Returns a string with the Reason for why the evalulation string is invalid
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property EvalReason() As String
            Get
                Return mEvalReason
            End Get
        End Property

    End Class
End Namespace

